<template>
  <h1>你查看的书籍ID---params是：{{$route.params.id}}</h1>
  <h1>你查看的书籍ID---query是：{{$route.query.id}}</h1>
  <h1>你查看的书籍ID---封装的是：{{getParameter("id")}}</h1>
  <p>图书名称是:{{book.title}}</p>
  <p>图书名称是:{{book.desc}}</p>
</template>

<script>
import Books from "@/service/Books";

export default {
  name: "BooksDetail",
  data() {
    return {book: {}}
  },
  created() {
    var bookid = this.getParameter("id");
    this.book = Books.find(item => item.id == bookid);
  },
  methods: {
    getParameter(field) {
      return this.$route.query[field] || this.$route.params[field];
    }
  }
}
</script>

<style scoped>

</style>